<template>
  <div class="cultivateCourse">
    <div class="tab">
      <div class="tabs" :class="[active == '0' ? 'se' : '']" @click="tapActive('0')">待报名</div>
      <div class="tabs" :class="[active == '1' ? 'se' : '']" @click="tapActive('1')">待上课</div>
    </div>
    <div class="goods">
      <van-list v-if="info.length > 0" class="list" v-model="loading" :finished="finished" finished-text="没有更多了" @load="loadMore">
        <template v-for="(item, index) in info">
          <div class="lis" v-if="active == '0'" :key="index">
            <div class="left">
              <img v-if="item.goods" :src="item.goods.thumb" alt="" />
            </div>
            <div class="right">
              <div v-if="item.goods" class="title">{{ item.goods.title }}</div>
              <div class="name">{{ item.course_type_name }}</div>
              <div class="quota">持有上课名额：{{ item.quota_num }}</div>
            </div>
          </div>
          <div class="lis" v-if="active == '1'" :key="index">
            <div class="left">
              <img v-if="item.course_term" :src="item.course_term.img" alt="" />
            </div>
            <div class="right">
              <div v-if="item.course_term" class="title">{{ item.course_term.name }}</div>
              <div class="name">{{ item.repeat_name }}</div>
            </div>
          </div>
        </template>
      </van-list>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      active: "0",
      getConfig: { client: "work", type: 17 }, //企业微信公共参数
      info: [],
      page: 1,
      loading: false,
      finished: false
    };
  },
  mounted() {
    this.page = 1;
    this.getData();
  },
  methods: {
    loadMore() {
      // console.log(this.loading,this.finished, "loading,finished");
      this.getData();
    },
    tapActive(key) {
      this.active = key;
      this.page = 1;
      this.info = [];
      this.finished = false;
      this.loading = false;
      this.getData();
    },
    async getData() {
      // console.log(this.finished,this.loading,'111111111111111111')
      if (this.finished && this.loading) {
        return;
      }
      let urlstr = "";
      let json = { page: this.page };
      if (this.active == "0") {
        urlstr = "plugin.wechat-chat-sidebar.frontend.controller.cultivateCourse.wait-quota";
      } else {
        urlstr = "plugin.wechat-chat-sidebar.frontend.controller.cultivateCourse.wait-clerk";
      }
      this.loading = true;
      let res = await $http.get(urlstr, json, "loading");
      this.loading = false;
      if (res.result === 1 && res.data.data) {
        if (this.page >= res.data.last_page || res.data.data.length < res.data.per_page) {
          this.finished = true;
        }
        // console.log('2222222222222',this.finished)
        this.info = this.page > 1 ? this.info.concat(res.data.data) : res.data.data;
        this.page = this.page + 1;
        // console.log(this.page,this.loading,this.finished,'ddddddddddddddd')
      } else {
        this.finished = true;
        this.$toast(res.msg);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.tab {
  display: flex;
  align-items: center;
  padding: 0.94rem;
  box-sizing: border-box;
  .tabs {
    font-weight: 500;
    font-size: 0.81rem;
    padding: 0.47rem 0.84rem;
    box-sizing: border-box;
    border-radius: 0.94rem;
    background: #fff;
    margin-right: 1.25rem;
  }
  .se {
    color: #f15353;
    border: 1px solid #f15353;
  }
  .tabs:last-child {
    margin-right: 0;
  }
}
.goods {
  // overflow: hidden;
  // background: #fff;
  height: 70vh;
  overflow-y: scroll;
  padding: 0 0.75rem;
  .lis {
    display: flex;
    padding: 0.94rem 0.75rem;
    background: #fff;
    .left {
      flex-shrink: 0;
      width: 5.81rem;
      height: 5.81rem;
      border-radius: 0.25rem;
      margin-right: 0.62rem;
      img {
        width: 100%;
        height: 100%;
        border-radius: 0.25rem;
      }
    }
    .right {
      flex: 1;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      padding-bottom: 0.66rem;
      padding-top: 0.5rem;
      .title {
        font-size: 0.94rem;
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 100%;
        text-align: left;
      }
      .name {
        padding: 0.31rem;
        box-sizing: border-box;
        border-radius: 0.25rem;
        background: #fef3e8;
        font-size: 0.75rem;
        color: #f38524;
        margin: 0.3rem 0;
      }
      .quota {
        font-size: 0.81rem;
        line-height: 0.98rem;
        color: #818181;
      }
    }
  }
}
</style>
